//
//  MSMeMenusView.m
//  MS
//
//  Created by Yuan on 13-2-20.
//  Copyright (c) 2013年 He Yuan. All rights reserved.
//

#import "MSMeMenusView.h"
#import "UIColor+ColorUtils.h"

@implementation MSMeMenusView

- (id)initWithOrigin:(CGPoint)point delegate:(id)delegate
{
    self = [super initWithFrame:CGRectZero];
    if (self)
    {
        UIImage *menusImg = [UIImage imageNamed:@"me_menus"];
        CGRect rect = CGRectZero;
        rect.origin = point;
        rect.size = menusImg.size;
        self.frame = rect;

        [self setNeedsDisplay];
        
        NSArray *menuTabs = [NSArray arrayWithObjects:HYLocalizedString(@"资料"),HYLocalizedString(@"收藏"),HYLocalizedString(@"评价"),HYLocalizedString(@"粉丝"), nil];
        CGFloat offset_x = 0.0f;
        CGFloat offset_y = 3.0f;
        CGFloat imgbtn_width = rect.size.width/[menuTabs count];
        CGFloat imgbtn_height = rect.size.height - offset_y*2;
        for (int idx = 0 ; idx < [menuTabs count]; idx++)
        {
            offset_x = idx*imgbtn_width;
            CGRect imgbtnFrame = CGRectMake(offset_x,offset_y,imgbtn_width,imgbtn_height);
            UIButton *imgbtn = [MSTool createButton:imgbtnFrame action:@selector(MenusClick:) delegate:delegate];
            UIImage *menustab = [UIImage imageNamed:[NSString stringWithFormat:@"me_menus_%d",idx+1]];
            imgbtn.tag = idx;
            [imgbtn addTarget:delegate action:@selector(MenusClick:) forControlEvents:UIControlEventTouchUpInside];
            [imgbtn setContentMode:UIViewContentModeScaleAspectFit];
            [imgbtn setImage:menustab forState:UIControlStateNormal];
            [imgbtn setTitle:[menuTabs objectAtIndex:idx] forState:UIControlStateNormal];
            [imgbtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
            [imgbtn setTitleColor:[UIColor colorWithString:@"#ff7ca6"] forState:UIControlStateHighlighted];
            [imgbtn setImage:menustab forState:UIControlStateHighlighted];
            [imgbtn setBackgroundColor:[UIColor clearColor]];
            [self addSubview:imgbtn];            
        }
    }
    return self;
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    UIImage *menusImg = [UIImage imageNamed:@"me_menus"];
    [menusImg drawInRect:rect];
    // Drawing code
}


@end
